package org.jcb.dao.data;

import java.util.Comparator;

public class ComparatorChinese implements Comparator {

	public int compare(Object o1, Object o2) {
		String[] st1 = (String[]) o1 ;
		String[] st2 = (String[]) o2 ;
		String car1 = replacePinyin(st1[1].toLowerCase()) ;
		String car2 = replacePinyin(st2[1].toLowerCase()) ;
		return (car1.compareTo(car2) );
	}
	
	private static String replacePinyin(String s) {
		String car1 = s.replaceAll("ā", "a1");
		car1 = car1.replaceAll("á", "a2");
		car1 = car1.replaceAll("ǎ", "a3");
		car1 = car1.replaceAll("à", "a4");

		car1 = car1.replaceAll("ē", "e1");
		car1 = car1.replaceAll("é", "e2");
		car1 = car1.replaceAll("ě", "e3");
		car1 = car1.replaceAll("è", "e4");
		
		car1 = car1.replaceAll("ī", "i1");
		car1 = car1.replaceAll("í", "i2");
		car1 = car1.replaceAll("ǐ", "i3");
		car1 = car1.replaceAll("ì", "i4");

		car1 = car1.replaceAll("ō", "o1");
		car1 = car1.replaceAll("ó", "o2");
		car1 = car1.replaceAll("ǒ", "o3");
		car1 = car1.replaceAll("ò", "o4");

		car1 = car1.replaceAll("ū", "u1");
		car1 = car1.replaceAll("ú", "u2");
		car1 = car1.replaceAll("ǔ", "u3");
		car1 = car1.replaceAll("ù", "u4");
		return car1 ;
	}	
	
}
